import os
import sys
import pandas
from gen_dates import quarterly_dates, weekly_dates

assert len(sys.argv) == 4

exp_name = sys.argv[1]
group_name = sys.argv[2]
use_order_latency_model = sys.argv[3]

assert use_order_latency_model in ['0', '1']

from products import product_groups

for (ex, c, quote, config) in product_groups[group_name]:
  for expiry in ['QUARTER', 'NEXT_WEEK', 'THIS_WEEK']:
    if quote == 'USDT' and expiry != 'QUARTER':
      continue

    if expiry == 'QUARTER':
      dates = quarterly_dates
    else:
      dates = weekly_dates

    dt = pandas.DatetimeIndex(dates.split('-'))
    concurrency = len(pandas.date_range(*dt))

    symbol = f'{c}-{quote}.{expiry}'
    exp = f'{exp_name}-{ex}-{symbol}'
    os.makedirs(f"out/{exp}", exist_ok=True)
    print(
        f'srun --job-name "search-{exp}" -c {concurrency} ./pyrunner ./cc/appcoin2/experimental/donggu/research/research.py {exp_name} {config} {ex} {symbol} {dates} 24H {use_order_latency_model} &> out/{exp}/log.txt &'
    )

